home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Programming / ace_gpl_release / src / lib / c / pow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-04  |  1.8 KB  |  60 lines

  1. /*
  2. ** ACE library (db.lib) module: Exponentiation.
  3. ** Copyright (C) 1998 David Benn
  4. ** 
  5. ** This program is free software; you can redistribute it and/or
  6. ** modify it under the terms of the GNU General Public License
  7. ** as published by the Free Software Foundation; either version 2
  8. ** of the License, or (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program; if not, write to the Free Software
  17. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18. **
  19. ** Author: David J Benn
  20. **   Date: 5th November 1995
  21. */
  22.  
  23. /* External variables */
  24. extern unsigned long MathIeeeSingTransBase;
  25.  
  26. /* External function declarations */
  27. extern float SPFieee();    
  28. extern float SPTieee();    
  29. extern float SPPow();
  30. extern float IEEESPPow();    
  31.  
  32. /* Exponentiation function */
  33. float power(y,x)
  34. float y;
  35. float x;
  36. {
  37. /*
  38. ** Returns x raised to the power of y.
  39. ** Uses the IEEE single-precision function
  40. ** IEEESPPow() because it is more accurate
  41. ** and handles negative base values correctly.
  42. **
  43. ** The parameters and result are converted to
  44. ** and from IEEE format respectively. 
  45. **
  46. ** Only in the event that the IEEE SP library
  47. ** can't be opened will the FFP SPPow() function
  48. ** be used. Note that this should only happen on
  49. ** systems with an OS prior to Release 2.0. Note
  50. ** also that bogus results will be obtained via the
  51. ** FFP function if the base is negative. This doesn't
  52. ** seem to be worth fixing since only old systems
  53. ** will be affected.    
  54. */
  55.     if (MathIeeeSingTransBase)
  56.         return SPFieee(IEEESPPow(SPTieee(y),SPTieee(x)));
  57.     else
  58.         return SPPow(y,x);
  59. }
  60.